home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / ada / c01lab1.zip / ADAWKBK / SOL2-2.ADA < prev    next >
Text File  |  1992-11-11  |  1KB  |  45 lines

  1. -- Problem 2.2
  2. -- by Rick Conn
  3. with Text_IO;
  4. procedure Main is
  5.  
  6.   type SPEED is new FLOAT range 0.0 .. 1_000_000.0;      -- MPH
  7.   type TIME is new FLOAT range 0.0 .. 24.0;              -- hours
  8.   type DISTANCE is new FLOAT range 0.0 .. 24_000_000.0;  -- miles
  9.  
  10.   Current_Speed     : SPEED;
  11.   Elapsed_Time      : TIME;
  12.   Computed_Distance : DISTANCE;
  13.  
  14.   package Float_IO is new Text_IO.Float_IO (FLOAT);
  15.  
  16.   function "*" (S : in SPEED;
  17.                 T : in TIME)
  18.       return DISTANCE is
  19.   begin
  20.     return DISTANCE (FLOAT(S) * FLOAT(T));
  21.   end "*";
  22.  
  23. begin -- Main
  24.  
  25.   Text_IO.Put_Line ("Speed      Time  Distance");
  26.   for S in 0 .. 5 loop
  27.     Current_Speed := SPEED (FLOAT(S) * 200_000.0);
  28.  
  29.     for T in 0 .. 3 loop
  30.       Elapsed_Time := TIME (FLOAT(T) * 8.0);
  31.  
  32.       Computed_Distance := Current_Speed * Elapsed_Time;
  33.  
  34.       Float_IO.Put (FLOAT(Current_Speed), 7, 1, 0);
  35.       Text_IO.Put("  ");
  36.       Float_IO.Put (FLOAT(Elapsed_Time), 2, 1, 0);
  37.       Text_IO.Put("  ");
  38.       Float_IO.Put (FLOAT(Computed_Distance), 8, 1, 0);
  39.       Text_IO.New_Line;
  40.  
  41.     end loop;
  42.   end loop;
  43.  
  44. end Main;
  45.